<?php

namespace plugin\webman\gateway;

use GatewayWorker\Lib\Gateway;

class Events
{
    public static function onWorkerStart($worker): void
    {
        echo "WorkerStart\n";
    }

    public static function onConnect($client_id): void
    {
        Gateway::sendToCurrentClient("Your client_id is $client_id");
    }

    public static function onWebSocketConnect($client_id, $data): void
    {
        var_export($data);
        if (!isset($data['get']['token'])) {
            Gateway::closeClient($client_id);
        }
    }

    public static function onMessage($client_id, $message): void
    {
        var_dump($message);
        Gateway::sendToClient($client_id, "receive message $message");
    }

    public static function onClose($client_id)
    {

    }

}
